package com.pinyougou.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;
import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>title:com.pinyougou.manager.controller</p>
 * name:orang
 * date:2018/9/11 0011-21:53
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Reference
    private BrandService brandService;

    //查询所有品牌数据
    @RequestMapping("/findAll")
    public List<TbBrand> findAll(){
        return brandService.findAll();
    }

    //根据分页查询品牌数据
    @RequestMapping("/findPage")
    public PageResult findPage(int page,int rows){
        return brandService.findPage(page,rows);
    }

    //添加品牌信息
    @RequestMapping("/add")
    public Result add(@RequestBody TbBrand tbBrand){
        try{
            brandService.add(tbBrand);
            return new Result(true,"品牌添加成功!");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"品牌添加失败!");
        }

    }

    //更改品牌信息
    @RequestMapping("/update")
    public Result update(@RequestBody TbBrand tbBrand){
        try{
            brandService.update(tbBrand);
            return new Result(true,"品牌修改成功!");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"品牌修改失败!");
        }
    }

    //根据id查询品牌信息
    @RequestMapping("/findOne")
    public TbBrand findOne(Long id){
        return brandService.findOne(id);
    }

    //根据前端传来的ID集合删除品牌
    @RequestMapping("/delect")
    public Result delect(Long[] ids){
        try{
            brandService.delect(ids);
            return new Result(true,"品牌删除成功!");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"品牌删除失败!");
        }
    }

    //查询加分页
    @RequestMapping("/search")
    public PageResult result(@RequestBody TbBrand tbBrand,int page,int rows){
        return brandService.findPage(tbBrand,page,rows);
    }

    /**
     * 查询品牌数据
     */
    @RequestMapping("/selectOptionList")
    public List<Map> selectOptionList(){
        return brandService.selectOptionList();
    }

}
